package com.muxi.association.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZXW
 */
public class ParameterDealUtil {

    /**
     * @param ss 不定数参数
     * @return 参数都不为null或者空 返回false 否则返回true
     */
    public static boolean parametersStringIsEmpty(String... ss) {
        for(String s : ss) {
            if (s == null || "".equals(s)) {
                return true;
            }
        }
        return false;
    }

    public static boolean parametersNumberIsEmpty(Object... objs) {
        for(Object obj : objs) {
            if (obj == null) {
                return true;
            }
        }
        return false;
    }

    public static boolean parametersArrayIsEmpty(Object[] objects) {
        return objects == null || objects.length == 0 ? true : false;
    }

    public static String parameterNullHandle(String s) {
        return "".equals(s) || null == s ? null : s.trim();
    }

    public static ArrayList<Integer> pageParameterDeal(Integer pageNum, Integer limit) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (limit == null) {
            limit = 10;
        }
        ArrayList<Integer> list = new ArrayList<Integer>();
        list.add(pageNum);
        list.add(limit);
        return list;
    }

    public static List<Integer> stringSplitArray(String str) {
        List<Integer> list = null;
        if (!parametersStringIsEmpty(str)) {
            String[] ss = str.split(",");
            list = new ArrayList<>();
            for (String s : ss) {
                list.add(Integer.parseInt(s));
            }
        }
        return list;
    }

    public static List<Integer> stringSplitToArray(String str) {
        List<Integer> list = new ArrayList<>();
        if (!parametersStringIsEmpty(str)) {
            String[] ss = str.split(",");
            for (String s : ss) {
                list.add(Integer.parseInt(s));
            }
        }
        return list;
    }
}
